package com.biyeshengjiuye.controller.enterprise;

import com.alibaba.fastjson.JSON;
import com.biyeshengjiuye.entity.Enterprise;
import com.biyeshengjiuye.service.EnterpriseService;
import com.biyeshengjiuye.utils.SystemConstant;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;


@RestController
@RequestMapping("/enterprise")
public class EnterpriseController {

    @Resource
    private EnterpriseService enterpriseService;

    @RequestMapping("/login")
    public String login(String phone, String password, HttpSession session){
        Map<String,Object> map = new HashMap<String, Object>();
        Enterprise enterprise = enterpriseService.login(phone,password);
        if (enterprise != null && enterprise.getE_state().equals("通过")){
            session.setAttribute(SystemConstant.ENTERPRISELOGIN,enterprise);
            map.put(SystemConstant.SUCCESS,true);
        }else if (enterprise != null && enterprise.getE_state().equals("审核中")){
            map.put(SystemConstant.SUCCESS,false);
            map.put(SystemConstant.MESSAGE,"该账号还在审核当中，登录失败");
        }else {
            map.put(SystemConstant.SUCCESS,false);
            map.put(SystemConstant.MESSAGE,"账号密码错误，登录失败");
        }
        return JSON.toJSONString(map);
    }





}
